package com.service.vod.controller;

import com.service.utils.ResultVo;
import com.service.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.util.Map;

@RestController
@Api(description = "阿里云视频点播管理")
@RequestMapping("vod")
public class VodController {

    @Autowired
    private VodService vodService;

    @GetMapping("getUrl/{id}")
    @ApiOperation("根据阿里云视频id获取视频播放地址")
    public ResultVo getUrl(@ApiParam(name = "id",value = "阿里云视频id",required = true) @PathVariable String id){
        return ResultVo.ok().data("url",vodService.getUrl(id));
    }

    /**
     * 上传视频到阿里云视频点播中
     * 返回视频id 和 原始文件名
     * @param file
     * @return
     */
    @PostMapping("uploadVod")
    @ApiOperation("上传视频到阿里云视频点播中")
    public ResultVo uploadVod(@ApiParam(name = "file",value = "视频文件",required = true) @RequestParam("file") MultipartFile file){
        Map<String, Object> map = vodService.uploadVod(file);
        return ResultVo.ok().data(map);
    }

    /**
     *删除上传到阿里云的视频
     * @param id
     * @return
     */
    @DeleteMapping("delVod/{id}")
    @ApiOperation("删除上传到阿里云的视频")
    public ResultVo delVod(@ApiParam(name = "id",value = "要删除视频id",required = true) @PathVariable String id){
       vodService.delVod(id);
       return  ResultVo.ok();
    }


    @GetMapping("getPlayerAuth/{id}")
    @ApiOperation("根据视频id获取视频播放凭证")
    public ResultVo  getPlayerAuth(@PathVariable String id){
        String playerAuth =   vodService.getPlayerAuth(id);
        return  ResultVo.ok().data("playerAuth",playerAuth);
    }


}
